package WebServices
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.xml.XMLNode;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;

	internal class SkillsAuditService extends HTTPService
	{
		private var m_fnSuccess:Function;
		private var m_fnFailure:Function;
		private var m_strRoot:String;
		
		public function SkillsAuditService(success:Function = null, failure:Function = null)
		{
			super(null, null);
			this.addEventListener( FaultEvent.FAULT, onFault, false, 0, true);
			this.addEventListener( ResultEvent.RESULT, onResult, false, 0, true);			
			m_fnSuccess = success;
			m_fnFailure = failure;
			contentType = CONTENT_TYPE_FORM;	
			resultFormat = RESULT_FORMAT_XML;
			method = "POST";
		}


		public function setCallbacks(success:Function, failure:Function):void
		{
			m_fnSuccess = success;
			m_fnFailure = failure;			
		}
	
		public function onResult(result:ResultEvent):void
		{
			if(m_fnSuccess != null)
			{
				var xmlResult:XML = new XML(result.result as XMLNode);
				if(xmlResult.name() == "RequestProcessingError")
				{
					var strErrorNo:String = xmlResult.ErrorCode;
					var strErrorDesc:String = xmlResult.ErrorDescription;
					m_fnFailure(new Error("Call to Server failed with Error #" +strErrorNo + ".\n\n"+ strErrorDesc)); 					 
				}
				else
				{
					m_fnSuccess(xmlResult);
				}
			}
			m_fnSuccess = null;
			m_fnFailure = null;
		} 
		
		private function onFault(result:FaultEvent):void
		{
			if(m_fnFailure != null)
			{
				m_fnFailure(result.fault);
			}
			m_fnSuccess = null;
			m_fnFailure = null;
		} 
	}
}